package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bussiness.domain.SysBusinessCheckList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.SysBusinessPolicy;
import com.ruoyi.bussiness.service.ISysBusinessPolicyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务_政策Controller
 *
 * @author ruoyi
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/bussiness/policy")
public class SysBusinessPolicyController extends BaseController
{
    @Autowired
    private ISysBusinessPolicyService sysBusinessPolicyService;

    /**
     * 查询业务_政策列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBusinessPolicy sysBusinessPolicy)
    {
        startPage();
        List<SysBusinessPolicy> list = sysBusinessPolicyService.selectSysBusinessPolicyList(sysBusinessPolicy);
        return getDataTable(list);
    }

    /**
     * 导出业务_政策列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:policy:export')")
    @Log(title = "业务_政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBusinessPolicy sysBusinessPolicy)
    {
        List<SysBusinessPolicy> list = sysBusinessPolicyService.selectSysBusinessPolicyList(sysBusinessPolicy);
        ExcelUtil<SysBusinessPolicy> util = new ExcelUtil<SysBusinessPolicy>(SysBusinessPolicy.class);
        util.exportExcel(response, list, "业务_政策数据");
    }

    /**
     * 获取业务_政策详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:policy:query')")
    @GetMapping(value = "/{policyId}")
    public AjaxResult getInfo(@PathVariable("policyId") Long policyId)
    {
        return success(sysBusinessPolicyService.selectSysBusinessPolicyByPolicyId(policyId));
    }

    /**
     * 新增业务_政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:policy:add')")
    @Log(title = "业务_政策", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBusinessPolicy sysBusinessPolicy)
    {
        return toAjax(sysBusinessPolicyService.insertSysBusinessPolicy(sysBusinessPolicy));
    }

    /**
     * 修改业务_政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:policy:edit')")
    @Log(title = "业务_政策", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBusinessPolicy sysBusinessPolicy)
    {
        return toAjax(sysBusinessPolicyService.updateSysBusinessPolicy(sysBusinessPolicy));
    }

    /**
     * 删除业务_政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:policy:remove')")
    @Log(title = "业务_政策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{policyIds}")
    public AjaxResult remove(@PathVariable Long[] policyIds)
    {
        return toAjax(sysBusinessPolicyService.deleteSysBusinessPolicyByPolicyIds(policyIds));
    }

    /**
     * 上移下移政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:policy:edit')")
    @Log(title = "政策", businessType = BusinessType.UPDATE)
    @PutMapping("/moveUpOrDown")
    public AjaxResult moveUpOrDown(@RequestBody SysBusinessPolicy entity)
    {
        return sysBusinessPolicyService.moveUpOrDown(entity);
    }

    /**
     * 置顶 置底政策
     */
    @PreAuthorize("@ss.hasPermi('bussiness:policy:edit')")
    @Log(title = "政策", businessType = BusinessType.UPDATE)
    @PutMapping("/pinToTopOrEnd")
    public AjaxResult pinToTopOrEnd(@RequestBody SysBusinessPolicy entity)
    {
        return sysBusinessPolicyService.pinToTopOrEnd(entity);
    }
}
